/*
 * Time : 2022/12/3 18:40
 * Auth : weixinlong
 * Email : weixinlong@buaa.edu.cn
 * File : response.go
 */

package util

import (
	"net/http"

	"github.com/cloudwego/hertz/pkg/app"
	"github.com/cloudwego/hertz/pkg/common/utils"
)

func ResponseSuccess(c *app.RequestContext, data interface{}) {
	c.JSON(200, utils.H{
		"code":    "200",
		"message": "success",
		"data":    data,
	})
}

func ResponseFail(c *app.RequestContext, message interface{}) {
	c.JSON(400, utils.H{
		"code":    "400",
		"message": message,
		"data":    "null",
	})
}

func ErrMessage(c *app.RequestContext, code int, message interface{}) {
	c.JSON(code, utils.H{
		"message": message,
	})
}

func BadRequest(c *app.RequestContext, err error) {
	c.JSON(http.StatusBadRequest, utils.H{
		"message": err.Error(),
	})
}

func NotFound(c *app.RequestContext) {
	c.JSON(http.StatusNotFound, utils.H{
		"message": "not found",
	})
}
